var mergeTwoLists = function (list1, list2) {
  const len = list1.length + list2.length;
  let ans = [],
    left = 0,
    right = 0;
  for (let index = 0; index < len; index++) {
    if (list1[left] < list2[right]) {
      ans.push(list1[left]);
      left++;
    } else {
      ans.push(list2[right]);
      right++;
    }
  }
  return ans;
};
const ans = mergeTwoLists([1, 3, 5], [2, 4, 6]);
console.log("ans: ", ans);

var mergeTwoLists = function (l1, l2) {
  if (l1 === null) {
    return l2;
  } else if (l2 === null) {
    return l1;
  } else if (l1.val < l2.val) {
    l1.next = mergeTwoLists(l1.next, l2);
    return l1;
  } else {
    l2.next = mergeTwoLists(l1, l2.next);
    return l2;
  }
};
